package com.sun.showcase.controller.mall;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

import com.sun.showcase.biz.mall.service.CollectionService;
import com.sun.showcase.pojo.DataGrid;
import com.sun.showcase.pojo.Result;
import com.sun.showcase.client.domain.mall.Collection;
import com.sun.showcase.client.query.mall.CollectionQuery;

@Controller
@RequestMapping(value="/mall/collection") 
public class CollectionController{
	
	@Autowired
	private CollectionService collectionService;
	
	private Result result = new Result();
	/**
	 * 跳转到Collection管理页面
	 * 
	 * @return
	 */
	@RequestMapping(value="goCollection")
	public String goCollection() {
		return "mall/collection";
	}
	/**
	 * 跳转到Collection新增页面
	 * 
	 * @return
	 */
	@RequestMapping(value="handleCollection")
	public String handleCollection(@RequestParam(value="id",required=false) Long id ,ModelMap map) {
		return "mall/collection_rowEdit";
	}

	/**
	 * 跳转到查看desc页面
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="showDesc")
	public Collection showDesc(CollectionQuery collectionQuery) {
		return collectionService.get(collectionQuery);
	}

	/**
	 * 获得分页数据表格
	 */
	@ResponseBody
	@RequestMapping(value = "/datagrid")
	public DataGrid datagrid(CollectionQuery collectionQuery) {
		return collectionService.datagrid(collectionQuery);
	}
	

	/**
	 * 添加一个Collection
	 */
	@ResponseBody
	@RequestMapping(value="add")
	public Result add(CollectionQuery collectionQuery) {
		collectionService.add(collectionQuery);
		result.setSuccess(true);
		result.setMsg("添加成功！");
		return result;
	}

	/**
	 * 编辑Collection
	 */
	@ResponseBody
	@RequestMapping(value="edit")
	public Result edit(CollectionQuery collectionQuery) {
		collectionService.update(collectionQuery);
		result.setSuccess(true);
		result.setMsg("编辑成功！");
		return result;
	}

	/**
	 * 物理删除Collection
	 */
	@ResponseBody
	@RequestMapping(value="delete")
	public Result delete(CollectionQuery collectionQuery) {
		collectionService.delete(collectionQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
	
	/**
	 * 逻辑删除Collection
	 */
	@ResponseBody
	@RequestMapping(value="deletePt")
	public Result deletePt(CollectionQuery collectionQuery) {
		collectionService.deletePt(collectionQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
	/**
	 * 全部数据Collection
	 */
	@ResponseBody
	@RequestMapping(value="listAll")
	public Result listAll(CollectionQuery collectionQuery) {
		List<CollectionQuery> list = collectionService.listAll(collectionQuery);
		result.setSuccess(true);
		result.setMsg("成功！");
		result.setData(list);
		return result;
	}
}
